#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;

int longestConsecutive(vector<int> &nums)
{
    if (nums.empty())
    {
        return 0;
    }

    unordered_set<int> hashTalbe(nums.begin(),nums.end());

    int length = 0;
    for(int num : nums)
    {
        if(!hashTalbe.count(num - 1))//判断这个数字有没有资格做起始数字
        {
            int curLength = 1;
            int curNum = num;
            while(hashTalbe.count(curNum + 1))
            {
                curLength++;
                curNum++;
            }
            length = max(curLength,length);
        }
    }
    return length;
}

int main()
{
    vector<int> nums = {100, 4, 200, 1, 3, 2};
    cout << "Longest Consecutive Sequence Length: " << longestConsecutive(nums) << endl;
    return 0;
}
